package com.kafka;

import cn.hutool.json.JSONUtil;
import com.dto.UserDTO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

/**
 * @ClassName KafkaProduce
 * @Description kafka生产者
 * @Author zhengmw
 * @Data 2024/7/26 10:40
 */
@Slf4j
@Component
public class KafkaProduce {
    @Resource
    private KafkaTemplate<String, String> kafkaTemplate;

    public void send() {
        UserDTO userDTO = UserDTO.builder()
                .user_id("10001")
                .username("猪八戒")
                .password("123456")
                .phone("13421316478")
                .build();
        kafkaTemplate.send(TopicConstant.TOPIC_TEST, JSONUtil.toJsonStr(userDTO));
        log.info("消息发送成功");
    }
}
